<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('合同信息') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('申请标题')" prop="actTitle">
        <el-input v-model="queryParams.actTitle" :placeholder="$t('申请标题')" size="small" @keyup.enter.native="queryHandle" />
      </el-form-item>
      <el-form-item :label="$t('申请人')" prop="userName">
        <el-input v-model="queryParams.userName" :placeholder="$t('申请人')" clearable size="small" @keyup.enter.native="queryHandle" />
      </el-form-item>
      <el-form-item :label="$t('合同名称')" prop="name">
        <el-input
          v-model="queryParams.name"
          :placeholder="$t('合同名称')"
          clearable
          size="small"
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('对方签约主体名称')" prop="company">
        <el-input
          v-model="queryParams.company"
          :placeholder="$t('对方签约主体名称')"
          clearable
          size="small"
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('审批状态')" prop="actStatus">
        <dictSelect
          v-model="queryParams.actStatus"
          :clearable="true"
          dictionary="work_flow_status"
          :placeholder="$t('请选择')"
        />
      </el-form-item>
      <el-form-item :label="$t('收付款类型')" prop="isPayment">
        <dictSelect
          v-model="queryParams.isPayment"
          :clearable="true"
          dictionary="collection_payment_no"
          :placeholder="$t('请选择')"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['oa:contract:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t("新增") }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermi="['oa:contract:export']" type="warning" icon="el-icon-download" size="mini" @click="exportHandle">{{ $t("导出") }}</el-button>
      </el-col>
    </el-row>
    <el-table v-loading="loading" tooltip-effect="darkTable" :data="oaContractList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请标题')" align="left" prop="actTitle" show-overflow-tooltip width="250">
        <template slot-scope="scope">
          <el-link class="link-a" type="primary" @click="updateHandle(scope.row)">{{ scope.row.actTitle }}</el-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请人')" align="center" prop="userName" show-overflow-tooltip width="100px" />
      <el-table-column :label="$t('申请时间')" align="center" prop="applyTime" width="120">
        <template slot-scope="scope">
          <span class="money-text">{{ parseTime(scope.row.applyTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('合同编号')" align="center" prop="conteractNum" width="200" show-overflow-tooltip />
      <el-table-column :label="$t('合同名称')" align="center" prop="name" width="200" show-overflow-tooltip />
      <el-table-column :label="$t('合同金额') + $t('金额单位')" align="center" prop="money" width="110">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.money, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('对方签约主体名称')" align="center" prop="company" width="200px" show-overflow-tooltip />
      <el-table-column :label="$t('收付款类型')" align="center" prop="isPayment" :formatter="isPaymentFormat" width="100" />
      <el-table-column :label="$t('是否用印')" align="center" prop="isSeal" :formatter="isSealFormat" width="100" />
      <el-table-column :label="$t('合同摘要')" align="center" prop="abstracts" width="200" show-overflow-tooltip />
      <el-table-column fixed="right" :label="$t('审批状态')" align="center" width="120">
        <template slot-scope="scope">
          <ProcessStatus :status="scope.row.actStatus" :act-id="scope.row.actId" />
        </template>
      </el-table-column>
      <el-table-column fixed="right" :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200px">
        <template slot-scope="scope">
          <!-- 启动流程，终止流程，修改，删除 四个按钮 -->
          <ListBtn :bus-data="scope.row" has-permi="oa:contract" />
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改合同信息对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm">
      <oaContractForm ref="oaContractForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listOaContract, delOaContract } from '@/api/oa/contract/oaContract'
import ProcessStatus from '@/components/Act/ProcessStatus'
import oaContractForm from './oaContractForm.vue'
export default {
    components: {
        oaContractForm,
        ProcessStatus
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 合同信息表格数据
          oaContractList: [],
          // 弹出层标题
          title: '合同信息',
          // 是否显示弹出层
          formOpen: false,
          // 查询参数
          queryParams: {
              applyUserId: '',
              name: undefined,
              company: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {
          },
          // 是否用印字典
          isPaymentOptions: [],
          // 付款类型字典
          isSealOptions: []
      }
  },
  created() {
      this.getList()
    this.getDicts('collection_payment_no').then(response => {
      this.isPaymentOptions = response.data
    })
    this.getDicts('sys_yes_no').then(response => {
      this.isSealOptions = response.data
    })
  },
  methods: {
    /** 查询合同信息列表 */
    getList() {
        this.loading = true
        listOaContract(this.queryParams).then(response => {
            this.oaContractList = response.rows
            this.total = response.total
            this.loading = false
        })
    },
    // 类型字典回显
    isPaymentFormat(row) {
      return this.selectDictLabel(this.isPaymentOptions, row.isPayment)
    },
    // 类型字典回显
    isSealFormat(row) {
      return this.selectDictLabel(this.isSealOptions, row.isSeal)
    },
    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            applyUserId: undefined,
            applyTime: undefined,
            name: undefined,
            money: undefined,
            typeOne: undefined,
            typeTwo: undefined,
            company: undefined,
            projectOrFund: undefined,
            isPayment: undefined,
            isSeal: undefined,
            useSealOne: undefined,
            useSealTwo: undefined,
            abstracts: undefined,
            createBy: undefined,
            updateBy: undefined,
            createTime: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.oaContractForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.oaContractForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delOaContract(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
        this.downLoadExcel('/contract/oaContract/export', this.queryParams)
    }
  }
}
</script>
